<?php

class Model_Tools {
	
	/**
	 * @desc delete all added slashes
	 *
	 * @param Object $object, returned by get method
	 * @return array
	 *
	 */
	public function stripslashes($object) {
		$result = array();
		foreach($object as $datas) {
			$temp = array();
			foreach($datas as $key => $value) {
				$temp[$key] = stripslashes($value);
			}
			$result[] = $temp;
		}
		
		return $result;
	}
	
	/**
	 * @desc add slashes to all array's datas
	 *
	 * @param Array $datas
	 * @return array
	 *
	 */
	public function addslashes($object) {
		$result = array();
		foreach($object as $datas) {
			$temp = array();
			foreach($datas as $key => $value) {
				$temp[$key] = stripslashes($value);
			}
			$result[] = $temp;
		}
		
		return $result;
	}	

	/**
	 * @desc replace every special caracters
	 *
	 * @param String $string
	 * @return String
	 *
	 */
	public function noSpecialChars($string) {
		$search = array ('@[éèêëÊË]@i','@[àâäÂÄ]@i','@[îïÎÏ]@i','@[ûùüÛÜ]@i','@[ôöÔÖ]@i','@[ç]@i','@[ ]@i','@[^a-zA-Z0-9_]@');
		$replace = array ('e','a','i','u','o','c','-','-');
		return preg_replace($search, $replace, $string);
		//return md5($in);
	}
	
	/**
	 * @desc get all 12 months whith number and name
	 * 
	 * @param null
	 * @return array
	 * 
	 */
	public function getMonths() {
		$month = array('01' => 'Janvier',
						'02' => 'Février',
						'03' => 'Mars',
						'04' => 'Avril',
						'05' => 'Mai',
						'06' => 'Juin',
						'07' => 'Juillet',
						'08' => 'Août',
						'09' => 'Septembre',
						'10' => 'Octobre',
						'11' => 'Novembre',
						'12' => 'Décembre',
						);
		return $month;
	}
	
	/**
	 * @desc change datetime format to timestamp
	 * @param Datetime $date
	 * 
	 * @return String
	 */
	function date_to_timestamp ($date) {
	    return preg_match('/^\s*(\d\d\d\d)-(\d\d)-(\d\d)\s*(\d\d):(\d\d):(\d\d)/', $date, $m)
	           ?  mktime($m[4], $m[5], $m[6], $m[2], $m[3], $m[1])
	           : 0;
	}
}

?>
